// pages/notice/notice.js
const { request } = require('../../utils/request.js');

Page({
  data: {
    notices: [] // 存储公告数据
  },

  onLoad() {
    this.fetchNotices();
  },

  // 获取公告数据
  fetchNotices() {
    request('/manager/notice/get', 'GET')
      .then(res => {
        console.log(res)
        if (res.code === '200') {
          res.data.forEach(item => {
            if (item.topic === null) {
                item.topic = "";
            }
        });
          this.setData({
            notices: res.data
          });
        } else {
          wx.showToast({
            title: '获取公告失败',
            icon: 'none'
          });
        }
      })
      .catch(() => {
        wx.showToast({
          title: '网络错误，请重试',
          icon: 'none'
        });
      });
  }
});
